
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>矢量数据投影转换 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../Fiona矢量数据处理/REDAME.md" />
    
    
    <link rel="prev" href="创建Shapefile文件并写入数据.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../Python基础/">
            
                <a href="../../Python基础/">
            
                    
                    Python基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../Python基础/Python环境搭建及基本数据类型.html">
            
                <a href="../../Python基础/Python环境搭建及基本数据类型.html">
            
                    
                    Python环境搭建及基本数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../Python基础/运算符及字符串.html">
            
                <a href="../../Python基础/运算符及字符串.html">
            
                    
                    运算符及字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../Python基础/序列与字典.html">
            
                <a href="../../Python基础/序列与字典.html">
            
                    
                    序列与字典
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../Python基础/流程控制语句.html">
            
                <a href="../../Python基础/流程控制语句.html">
            
                    
                    流程控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../Python基础/函数.html">
            
                <a href="../../Python基础/函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../Python基础/面向对象编程初识.html">
            
                <a href="../../Python基础/面向对象编程初识.html">
            
                    
                    面向对象编程初识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../../Python基础/面向对象编程高级.html">
            
                <a href="../../Python基础/面向对象编程高级.html">
            
                    
                    面向对象编程高级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../../Python基础/Python科学计算.html">
            
                <a href="../../Python基础/Python科学计算.html">
            
                    
                    Python科学计算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../../Python基础/空间数据处理环境搭建.html">
            
                <a href="../../Python基础/空间数据处理环境搭建.html">
            
                    
                    空间数据处理环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../空间数据基础/">
            
                <a href="../../空间数据基础/">
            
                    
                    空间数据基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../空间数据基础/空间参考系统.html">
            
                <a href="../../空间数据基础/空间参考系统.html">
            
                    
                    空间参考系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../空间数据基础/地图投影.html">
            
                <a href="../../空间数据基础/地图投影.html">
            
                    
                    地图投影
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../空间数据基础/空间数据.html">
            
                <a href="../../空间数据基础/空间数据.html">
            
                    
                    空间数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../">
            
                <a href="../">
            
                    
                    GDAL空间数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../GDAL简介.html">
            
                <a href="../GDAL简介.html">
            
                    
                    GDAL简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../GDAL数据基本操作.html">
            
                <a href="../GDAL数据基本操作.html">
            
                    
                    GDAL数据基本操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="打开栅格数据的正确方式.html">
            
                <a href="打开栅格数据的正确方式.html">
            
                    
                    打开栅格数据的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="栅格数据格式转换.html">
            
                <a href="栅格数据格式转换.html">
            
                    
                    栅格数据格式转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="栅格数据创建与保存.html">
            
                <a href="栅格数据创建与保存.html">
            
                    
                    栅格数据创建与保存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.4" data-path="读取HDF或者NetCDF格式的栅格数据.html">
            
                <a href="读取HDF或者NetCDF格式的栅格数据.html">
            
                    
                    读取HDF或者NetCDF格式的栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.5" data-path="栅格数据投影转换.html">
            
                <a href="栅格数据投影转换.html">
            
                    
                    栅格数据投影转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.6" data-path="栅格数据裁剪.html">
            
                <a href="栅格数据裁剪.html">
            
                    
                    栅格数据裁剪
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.7" data-path="打开Shapefile文件的正确方式.html">
            
                <a href="打开Shapefile文件的正确方式.html">
            
                    
                    打开Shapefile文件的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.8" data-path="创建Shapefile文件并写入数据.html">
            
                <a href="创建Shapefile文件并写入数据.html">
            
                    
                    创建Shapefile文件并写入数据
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.2.9" data-path="矢量数据投影转换.html">
            
                <a href="矢量数据投影转换.html">
            
                    
                    矢量数据投影转换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Fiona矢量数据处理/REDAME.md">
            
                <span>
            
                    
                    Fiona矢量数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                <a href="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                    
                    Fiona简介及Shapefile数据读取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                <a href="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                    
                    使用Fiona创建Shapefile矢量数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Rasterio栅格数据处理/README.md">
            
                <span>
            
                    
                    Rasterio栅格数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../Rasterio栅格数据处理/使用Rasterio读取栅格数据.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio读取栅格数据.html">
            
                    
                    使用Rasterio读取栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.2" data-path="../Rasterio栅格数据处理/使用Rasterio创建栅格数据.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio创建栅格数据.html">
            
                    
                    使用Rasterio创建栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.3" data-path="../Rasterio栅格数据处理/使用Rasterio做投影变换.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio做投影变换.html">
            
                    
                    使用Rasterio做投影变换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >矢量数据投影转换</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x77E2;&#x91CF;&#x6570;&#x636E;&#x6295;&#x5F71;&#x8F6C;&#x6362;">&#x77E2;&#x91CF;&#x6570;&#x636E;&#x6295;&#x5F71;&#x8F6C;&#x6362;</h1>
<p>&#x4F5C;&#x8005;&#xFF1A;&#x963F;&#x632F;</p>
<p>&#x90AE;&#x7BB1;&#xFF1A;tanzhenyugis@163.com</p>
<p>&#x535A;&#x5BA2;&#xFF1A;<a href="https://blog.csdn.net/theonegis/article/details/80089375" target="_blank">https://blog.csdn.net/theonegis/article/details/80089375</a></p>
<p>&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#xFF1A;2018-06-03</p>
<p>&#x58F0;&#x660E;&#xFF1A;&#x672C;&#x6587;&#x4E3A;&#x535A;&#x4E3B;&#x539F;&#x521B;&#x6587;&#x7AE0;&#xFF0C;&#x8F6C;&#x8F7D;&#x8BF7;&#x6CE8;&#x660E;&#x539F;&#x6587;&#x51FA;&#x5904;</p>
<hr>
<h2 id="&#x6848;&#x4F8B;&#x8BF4;&#x660E;">&#x6848;&#x4F8B;&#x8BF4;&#x660E;</h2>
<p>&#x63A5;&#x7740;&#x4E0A;&#x4E00;&#x7BC7;&#x535A;&#x6587;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5F97;&#x5230;&#x4E86;WGS84&#x5750;&#x6807;&#x7CFB;&#x4E0B;&#x7684;&#x4E2D;&#x56FD;&#x7701;&#x533A;&#x56FE;&#xFF0C;&#x800C;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4E2D;&#x56FD;&#x5730;&#x56FE;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x5272;&#x5706;&#x9525;&#x6295;&#x5F71;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x6211;&#x56FD;&#x4F4D;&#x4E8E;&#x4E2D;&#x7EAC;&#x5EA6;&#x5730;&#x533A;&#xFF0C;&#x4E2D;&#x56FD;&#x5730;&#x56FE;&#x548C;&#x5206;&#x7701;&#x5730;&#x56FE;&#x7ECF;&#x5E38;&#x91C7;&#x7528;&#x5272;&#x5706;&#x9525;&#x6295;&#x5F71;&#xFF0C;&#x4E2D;&#x56FD;&#x5730;&#x56FE;&#x7684;&#x4E2D;&#x592E;&#x7ECF;&#x7EBF;&#x5E38;&#x4F4D;&#x4E8E;&#x4E1C;&#x7ECF;105&#x5EA6;&#xFF0C;&#x4E24;&#x6761;&#x6807;&#x51C6;&#x7EAC;&#x7EBF;&#x5206;&#x522B;&#x4E3A;&#x5317;&#x7EAC;25&#x5EA6;&#x548C;&#x5317;&#x7EAC;47&#x5EA6;&#xFF0C;&#x800C;&#x5404;&#x7701;&#x7684;&#x53C2;&#x6570;&#x53EF;&#x6839;&#x636E;&#x5730;&#x7406;&#x4F4D;&#x7F6E;&#x548C;&#x8F6E;&#x5ED3;&#x5F62;&#x72B6;&#x521D;&#x6B65;&#x52A0;&#x4EE5;&#x5224;&#x5B9A;&#x3002;</p>
<p>&#x5728;<a href="http://spatialreference.org" target="_blank">SpatialReference</a>&#x4E2D;&#x67E5;&#x5230;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4F7F;&#x7528;&#x7684;&#x4E2D;&#x56FD;&#x5730;&#x56FE;&#x6295;&#x5F71;&#x4E3A;&#xFF1A;<a href="http://spatialreference.org/ref/sr-org/8657" target="_blank">http://spatialreference.org/ref/sr-org/8657</a></p>
<p>PROJ4&#x683C;&#x5F0F;&#x7684;&#x5B9A;&#x4E49;&#x4E3A;&#xFF1A;<code>+proj=aea +lat_1=25 +lat_2=47 +lat_0=30 +lon_0=105 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs</code></p>
<p>&#x4F7F;&#x7528;&#x8BE5;&#x6295;&#x5F71;&#xFF0C;&#x6211;&#x4EEC;&#x7956;&#x56FD;&#x96C4;&#x9E21;&#x624D;&#x4F1A;&#x53D8;&#x5F97;&#x96C4;&#x8D73;&#x8D73;&#x6C14;&#x6602;&#x6602;&#xFF0C;&#x66F4;&#x597D;&#x5730;&#x5C55;&#x73B0;&#x6211;&#x4EEC;&#x795E;&#x5DDE;&#x5927;&#x5730;&#x7684;&#x98CE;&#x91C7;&#x3002;</p>
<h2 id="&#x65B9;&#x6CD5;&#x4ECB;&#x7ECD;">&#x65B9;&#x6CD5;&#x4ECB;&#x7ECD;</h2>
<p>&#x8DDF;&#x6805;&#x683C;&#x6570;&#x636E;&#x6295;&#x5F71;&#x8F6C;&#x6362;&#x4E00;&#x6837;&#xFF0C;&#x4F7F;&#x7528;GDAL&#x5E93;&#xFF0C;&#x6211;&#x4EEC;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x77E2;&#x91CF;&#x6570;&#x636E;&#x7684;&#x91CD;&#x6295;&#x5F71;&#xFF1A;</p>
<ol>
<li><p>&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x5DE5;&#x5177;&#x53CA;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x547D;&#x4EE4;&#x884C;API&#x63A5;&#x53E3;&#x8FDB;&#x884C;&#x8F6C;&#x6362;&#xFF08;&#x7B80;&#x5355;&#xFF0C;&#x51C6;&#x786E;&#xFF0C;&#x5B9E;&#x8DF5;&#x4E2D;&#x4E00;&#x5B9A;&#x8981;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#xFF09;</p>
<p>GDAL&#x63D0;&#x4F9B;&#x4E86;<code>ogr2ogr</code>&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#x8FDB;&#x884C;&#x77E2;&#x91CF;&#x6570;&#x636E;&#x6295;&#x5F71;&#x8F6C;&#x6362;&#xFF0C;&#x547D;&#x4EE4;&#x5982;&#x4E0B;&#xFF1A;<code>ogr2ogr -t_srs &quot;+proj=aea +lat_1=25 +lat_2=47 +lat_0=30 +lon_0=105 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs &quot; China_Projected.shp China.shp</code></p>
<p><code>-t_srs</code>&#x9009;&#x9879;&#x5236;&#x5B9A;&#x8F93;&#x51FA;&#x6570;&#x636E;&#x6295;&#x5F71;&#xFF0C;&#x5F53;&#x7136;&#x53EF;&#x4EE5;&#x662F;ESPG&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;PROJ4&#x6216;&#x8005;OGC WKT&#x683C;&#x5F0F;&#x7684;&#x6295;&#x5F71;&#x5B9A;&#x4E49;&#x90FD;OK</p>
<p>GDAL&#x5BF9;&#x8BE5;&#x547D;&#x4EE4;&#x7684;&#x5C01;&#x88C5;&#x7684;C/C++&#x51FD;&#x6570;&#x662F;<code>GDALVectorTranslate()</code>,Python&#x4E2D;&#x662F;<code>gdal.VectorTranslate()</code></p>
</li>
<li><p>&#x4F7F;&#x7528;GDAL&#x63D0;&#x4F9B;&#x7684;&#x57FA;&#x672C;API&#x8FDB;&#x884C;&#x5B9E;&#x73B0;</p>
<p>&#x5982;&#x679C;&#x8981;&#x81EA;&#x5DF1;&#x5229;&#x7528;&#x57FA;&#x672C;API&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#x7684;&#x8BDD;&#xFF0C;&#x57FA;&#x672C;&#x601D;&#x8DEF;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>&#x5229;&#x7528;<code>osgeo.ogr.Driver.CreateDataSource()</code>&#x521B;&#x5EFA;&#x8F93;&#x51FA;&#x6570;&#x636E;</li>
<li>&#x6839;&#x636E;&#x6E90;&#x6587;&#x4EF6;&#x521B;&#x5EFA;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x7684;&#x5C5E;&#x6027;&#x5B57;&#x6BB5;&#x5B9A;&#x4E49;</li>
<li>&#x5229;&#x7528;<code>osgeo.osr.CoordinateTransformation</code>&#x5BF9;&#x8C61;&#x5C06;&#x6E90;&#x6587;&#x4EF6;&#x4E2D;&#x7684;Geometry&#x5BF9;&#x8C61;&#x8F6C;&#x4E3A;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x4E2D;&#x7684;Geometry&#x5BF9;&#x8C61;&#xFF08;&#x5176;&#x5B9E;&#x8D28;&#x662F;&#x8FDB;&#x884C;&#x4E0D;&#x540C;&#x6295;&#x5F71;&#x7CFB;&#x7EDF;&#x4E0B;&#x7A7A;&#x95F4;&#x51E0;&#x4F55;&#x4F53;&#x7684;&#x5750;&#x6807;&#x8F6C;&#x6362;&#xFF09;</li>
<li>&#x904D;&#x5386;&#x6E90;&#x6587;&#x4EF6;&#xFF0C;&#x4F9D;&#x6B21;&#x5C06;&#x6240;&#x6709;&#x51E0;&#x4F55;&#x4F53;&#x7684;Geometry&#x53CA;&#x5176;&#x5C5E;&#x6027;&#x5199;&#x5165;&#x76EE;&#x6807;&#x6587;&#x4EF6;</li>
</ul>
</li>
</ol>
<h2 id="&#x4EE3;&#x7801;&#x5B9E;&#x73B0;">&#x4EE3;&#x7801;&#x5B9E;&#x73B0;</h2>
<ol>
<li>&#x8C03;&#x7528;<code>gdal.VectorTranslate()</code>&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#x7684;&#x5305;&#x88C5;&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#xFF1A;</li>
</ol>
<pre><code class="lang-Python"><span class="hljs-keyword">from</span> osgeo <span class="hljs-keyword">import</span> gdal
<span class="hljs-keyword">import</span> os
os.environ[<span class="hljs-string">&apos;SHAPE_ENCODING&apos;</span>] = <span class="hljs-string">&quot;utf-8&quot;</span>


src_file = <span class="hljs-string">&apos;China.shp&apos;</span>
dst_file = <span class="hljs-string">&apos;China_Reprojected.shp&apos;</span>

<span class="hljs-comment"># &#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x884C;API&#x8F6C;&#x6362;</span>
<span class="hljs-comment"># &#x8F93;&#x51FA;&#x6570;&#x636E;&#x6295;&#x5F71;&#x5B9A;&#x4E49;&#xFF0C;&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF1A;http://spatialreference.org/ref/sr-org/8657</span>
srs_def = <span class="hljs-string">&quot;&quot;&quot;+proj=aea +lat_1=25 +lat_2=47 +lat_0=30 +lon_0=105 +x_0=0 +y_0=0 
+ellps=WGS84 +datum=WGS84 +units=m +no_defs &quot;&quot;&quot;</span>
gdal.VectorTranslate(dst_file, src_file, dstSRS=srs_def, reproject=<span class="hljs-keyword">True</span>)

src_ds = ogr.Open(src_file)
src_layer = src_ds.GetLayer(<span class="hljs-number">0</span>)
src_srs = src_layer.GetSpatialRef()  <span class="hljs-comment"># &#x8F93;&#x5165;&#x6570;&#x636E;&#x6295;&#x5F71;</span>
</code></pre>
<ol>
<li>&#x8C03;&#x7528;&#x57FA;&#x672C;API&#x51FD;&#x6570;&#x5B9E;&#x73B0;</li>
</ol>
<pre><code class="lang-Python"><span class="hljs-keyword">from</span> osgeo <span class="hljs-keyword">import</span> ogr
<span class="hljs-keyword">from</span> osgeo <span class="hljs-keyword">import</span> osr
<span class="hljs-keyword">import</span> os
os.environ[<span class="hljs-string">&apos;SHAPE_ENCODING&apos;</span>] = <span class="hljs-string">&quot;utf-8&quot;</span>


src_file = <span class="hljs-string">&apos;China.shp&apos;</span>
dst_file = <span class="hljs-string">&apos;China_Reprojected.shp&apos;</span>

src_ds = ogr.Open(src_file)
src_layer = src_ds.GetLayer(<span class="hljs-number">0</span>)
src_srs = src_layer.GetSpatialRef()  <span class="hljs-comment"># &#x8F93;&#x5165;&#x6570;&#x636E;&#x6295;&#x5F71;</span>

<span class="hljs-comment"># &#x8F93;&#x51FA;&#x6570;&#x636E;&#x6295;&#x5F71;&#x5B9A;&#x4E49;&#xFF0C;&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF1A;http://spatialreference.org/ref/sr-org/8657</span>
srs_def = <span class="hljs-string">&quot;&quot;&quot;+proj=aea +lat_1=25 +lat_2=47 +lat_0=30 +lon_0=105 +x_0=0 +y_0=0 
+ellps=WGS84 +datum=WGS84 +units=m +no_defs &quot;&quot;&quot;</span>
dst_srs = osr.SpatialReference()
dst_srs.ImportFromProj4(srs_def)

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x8F6C;&#x6362;&#x5BF9;&#x8C61;</span>
ctx = osr.CoordinateTransformation(src_srs, dst_srs)

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x8F93;&#x51FA;&#x6587;&#x4EF6;</span>
driver = ogr.GetDriverByName(<span class="hljs-string">&apos;ESRI Shapefile&apos;</span>)
dst_ds = driver.CreateDataSource(dst_file)
dst_layer = dst_ds.CreateLayer(<span class="hljs-string">&apos;province&apos;</span>, dst_srs, ogr.wkbPolygon)

<span class="hljs-comment"># &#x7ED9;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x56FE;&#x5C42;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;&#x5B9A;&#x4E49;</span>
layer_def = src_layer.GetLayerDefn()
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(layer_def.GetFieldCount()):
    field_def = layer_def.GetFieldDefn(i)
    dst_layer.CreateField(field_def)

<span class="hljs-comment"># &#x5FAA;&#x73AF;&#x904D;&#x5386;&#x6E90;Shapefile&#x4E2D;&#x7684;&#x51E0;&#x4F55;&#x4F53;&#x6DFB;&#x52A0;&#x5230;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x4E2D;</span>
src_feature = src_layer.GetNextFeature()
<span class="hljs-keyword">while</span> src_feature:
    geometry = src_feature.GetGeometryRef()
    geometry.Transform(ctx)
    dst_feature = ogr.Feature(layer_def)
    dst_feature.SetGeometry(geometry)  <span class="hljs-comment"># &#x8BBE;&#x7F6E;Geometry</span>
    <span class="hljs-comment"># &#x4F9D;&#x6B21;&#x8BBE;&#x7F6E;&#x5C5E;&#x6027;&#x503C;</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(layer_def.GetFieldCount()):
        field_def = layer_def.GetFieldDefn(i)
        field_name = field_def.GetName()
        dst_feature.SetField(field_name, src_feature.GetField(field_name))
    dst_layer.CreateFeature(dst_feature)
    dst_feature = <span class="hljs-keyword">None</span>
    src_feature = <span class="hljs-keyword">None</span>
    src_feature = src_layer.GetNextFeature()
dst_ds.FlushCache()

<span class="hljs-keyword">del</span> src_ds
<span class="hljs-keyword">del</span> dst_ds

<span class="hljs-comment"># &#x521B;&#x5EFA;Shapefile&#x7684;prj&#x6295;&#x5F71;&#x6587;&#x4EF6;</span>
dst_srs.MorphToESRI()
(dst_path, dst_name) = os.path.split(dst_file)
<span class="hljs-keyword">with</span> open(dst_path + os.pathsep + dst_name + <span class="hljs-string">&apos;.prj&apos;</span>, <span class="hljs-string">&apos;w&apos;</span>) <span class="hljs-keyword">as</span> f:
    f.write(dst_srs.ExportToWkt())
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="创建Shapefile文件并写入数据.html" class="navigation navigation-prev " aria-label="Previous page: 创建Shapefile文件并写入数据">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../Fiona矢量数据处理/REDAME.md" class="navigation navigation-next " aria-label="Next page: Fiona矢量数据处理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"矢量数据投影转换","level":"1.4.2.9","depth":3,"next":{"title":"Fiona矢量数据处理","level":"1.4.3","depth":2,"path":"GDAL空间数据处理/Fiona矢量数据处理/REDAME.md","ref":"GDAL空间数据处理/Fiona矢量数据处理/REDAME.md","articles":[{"title":"Fiona简介及Shapefile数据读取","level":"1.4.3.1","depth":3,"path":"GDAL空间数据处理/Fiona矢量数据处理/Fiona简介及Shapefile数据读取.md","ref":"GDAL空间数据处理/Fiona矢量数据处理/Fiona简介及Shapefile数据读取.md","articles":[]},{"title":"使用Fiona创建Shapefile矢量数据","level":"1.4.3.2","depth":3,"path":"GDAL空间数据处理/Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.md","ref":"GDAL空间数据处理/Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.md","articles":[]}]},"previous":{"title":"创建Shapefile文件并写入数据","level":"1.4.2.8","depth":3,"path":"GDAL空间数据处理/GDAL数据基本操作/创建Shapefile文件并写入数据.md","ref":"GDAL空间数据处理/GDAL数据基本操作/创建Shapefile文件并写入数据.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"GDAL空间数据处理/GDAL数据基本操作/矢量数据投影转换.md","mtime":"2019-03-22T18:52:30.713Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-22T20:04:12.549Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

